package cn.sinata.wanglin.mine.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import com.xilada.xldutils.activitys.TitleActivity;
import com.xilada.xldutils.utils.ActivityUtil;
import com.xilada.xldutils.utils.SharedPreferencesUtils;
import com.xilada.xldutils.utils.StringUtils;
import com.xilada.xldutils.view.TwoTextLinearView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sinata.wanglin.R;
import cn.sinata.wanglin.commonutils.Constant;

public class AccountSafeActivity extends TitleActivity {
    @BindView(R.id.ttlv_bind_phone)
    TwoTextLinearView ttlv_bind_phone;//

    @Override
    protected int setContentId() {
        return R.layout.activity_account_safe;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("帐号安全");
        String phone= SharedPreferencesUtils.getString(Constant.SP_PHONE);
        if(!TextUtils.isEmpty(phone)){
            ttlv_bind_phone.setRightText(StringUtils.hidePhoneNumber(phone));
        }
    }

    @OnClick({R.id.ttlv_bind_phone,R.id.tv_password})
    void onClick(View v){
        String phone= SharedPreferencesUtils.getString(Constant.SP_PHONE);
        switch (v.getId()){
            case R.id.ttlv_bind_phone:

                if(TextUtils.isEmpty(phone)){
                    ActivityUtil.create(mContext).go(BindPhoneForAuthActivity.class).startForResult(9);
                }else{
                    ActivityUtil.create(mContext).go(BindPhoneActivity.class).startForResult(1);
                }

                break;
            case R.id.tv_password:
                if(TextUtils.isEmpty(phone)){
                    showToast("请先绑定手机！");
                   return;
                }
                ActivityUtil.create(mContext).go(ModifyPasswordActivity.class).startForResult(2);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK){
           finish();
        }
    }
}
